﻿namespace Sage.FreeSqlManager.Tenant
{
    /// <summary>
    /// 租户管理器 - 负责管理当前租户上下文
    /// </summary>
    /// <remarks>
    /// 使用AsyncLocal实现在异步代码流中保持租户上下文
    /// </remarks>
    public static class TenantManager
    {
        /// <summary>
        /// AsyncLocal存储，确保异步环境中租户ID正确传递
        /// </summary>
        private static readonly AsyncLocal<long> _asyncLocal = new();

        ///// <summary>
        ///// AsyncLocal存储，确保异步环境中租户ID(Guid)正确传递
        ///// </summary>
        //private static readonly AsyncLocal<Guid> _asyncLocalGuid = new();

        /// <summary>
        /// 获取或设置当前租户ID
        /// </summary>
        /// <value>当前租户ID，0表示未设置租户</value>
        public static long Current
        {
            get => _asyncLocal.Value;
            set => _asyncLocal.Value = value;
        }


        ///// <summary>
        ///// 获取或设置当前租户ID(Guid)
        ///// </summary>
        ///// <value>当前租户ID(Guid)，0表示未设置租户</value>
        //public static Guid CurrentGuid
        //{
        //    get => _asyncLocalGuid.Value;
        //    set => _asyncLocalGuid.Value = value;
        //}
    }
}